package com.xuecheng.content.api;

import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.M
 * @version 1.0
 * @description 课程计划管理相关的接口
 * @date 2023/2/14 11:25
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachplanController {

    @Autowired
    TeachplanService teachplanService;

   @ApiOperation("查询课程计划树形结构")
   //查询课程计划  GET /teachplan/22/tree-nodes
   @GetMapping("/teachplan/{courseId}/tree-nodes")
 public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
       List<TeachplanDto> teachplanTree = teachplanService.findTeachplanTree(courseId);

       return teachplanTree;
   }

    /**
     * @description 课程计划创建或修改
     * @param teachplan
     */
    @ApiOperation("课程计划创建或修改")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_plan')")
    @PostMapping("/teachplan")
    public void saveOrUpdateTeachPlan( @RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }

    /**
     * @description 删除课程计划信息
     * @param id 课程计划的 id
     * @return void
     * @author: woldier
     * @date: 2023/3/7 20:59
     */
    @ApiOperation("删除课程计划信息")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_plan')")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachPlan(@PathVariable Long id) {
        teachplanService.deleteTeachPlan(id);
    }

    /**
     * @description 课程下移
     * @param id
     * @return void
     * @author: woldier
     * @date: 2023/3/7 22:20
     */
    @ApiOperation("移动课程计划信息位置下移")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_plan')")
    @PostMapping("/teachplan/movedown/{id}")
    public void moveDown(@PathVariable Long id) {
        teachplanService.move(id,Boolean.TRUE);
    }

    /**
     * @description 课程上移
     * @param id
     * @return void
     * @author: woldier
     * @date: 2023/3/7 22:20
     */
    @ApiOperation("移动课程计划信息位置上移")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_plan')")
    @PostMapping("/teachplan/moveup/{id}")
    public void moveUp(@PathVariable Long id) {
        teachplanService.move(id,Boolean.FALSE);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_plan')")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }
}
